<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>列表动画</title>
    <script src="../../lib/vue.js"></script>
    <style>
        li {
            border: 1px dashed #999;
            margin: 5px;
            line-height: 35px;
            padding-left: 5px;
            font-size: 12px;
            width: 100%;
        }

        li:hover {
            background-color: darkcyan;
            transition: all 0.8s ease;
        }

        .v-enter,
        .v-leave-to{
            opacity: 0;
            transform: translateY(80px);
        }

        .v-enter-active,
        .v-leave-active {
            transition: all 0.6s ease;
        }

        /*固定写法*/
        /* 下面的 .v-move 和 .v-leave-active 配合使用，能够实现列表后续的元素，渐渐地漂上来的效果 */
        .v-move {
            transition: all 0.6s ease;
        }
        .v-leave-active{
            position: absolute;
        }
    </style>
</head>
<body>
    <div id="app">
        <label>
            id:<input v-model="id" />
        </label>
        <label>
            name:<input v-model="name" />
        </label>
        <input type="button" @click="add" value="添加" />


        <ul>
            <transition-group appear tag="ul">
                <li v-for="(item,i) in list" :key="item.id" @click="del(i)">
                    id==={{ item.id }}  name===={{ item.name }}
                </li>
            </transition-group>
        </ul>

    </div>

    <script>
        var vue = new Vue({
            el : '#app',
            data:{
                id:'',
                name:'',
                list:[
                    {id:1,name:'kobe'},
                    {id:2,name:'james'},
                    {id:3,name:'curry'}
                ]
            },
            methods:{
                add(){
                    this.list.push({id:this.id,name:this.name})
                },
                del(i){
                    this.list.splice(i,1);
                }
            }
        })
    </script>
</body>
</html>